<template>
   <PostWriter :post="post" @save="handleSave" />
</template>
<script lang="ts">
import {defineComponent} from "vue"
import PostWriter from "@/components/PostWriter.vue"
import {Post} from "@/types";
import moment from "moment";
import { useStore } from "@/store";
import { useRouter } from "vue-router";
export default defineComponent({
    name:"NewPost",
    components:{
        PostWriter
    },
    setup(){
        const post:Post={
            id:-1,
            title:"米修在线",
            markdown:'## vue fdfd  \n dsjufisladfiasf',
            html:'',
            authorId:0,
            created:moment()
        }
        const store=useStore()
        const router=useRouter()
        const handleSave=async (post:Post)=>{
            // 数据存储
            await store.cteatePosts(post)
            // 页面返回
            router.push('/') 
        }

        return {post,handleSave}
    }
})
</script>